<template>
	<div class="zhibodarenbang">
		<div class="haowubang_header">
			<div class="haowubang_header1">
				<div>周榜</div>
				<div>
					<el-date-picker
					  v-model="value2"
					  type="daterange"
					  align="right"
					  unlink-panels
					  range-separator="至"
					  start-placeholder="开始日期"
					  end-placeholder="结束日期"
					  :picker-options="pickerOptions">
					</el-date-picker>
				</div>
				<div>数据说明<i class="el-icon-question"></i></div>
			</div>
			<div class="haowubang_header2">
				<span>更新日期：</span>
				<span>2020-10-28 12：07</span>
				<span v-loading.fullscreen.lock="fullscreenLoading" @click="xiazai"><i class="el-icon-printer"></i>导出数据</span>
			</div>
		</div>
		
		<div class="haowubiao">
			<table cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<th>排名</th>
						<th></th>
						<th>达人名称</th>
						<th>粉丝量</th>
						<th>直播热度</th>
					</tr>
				</thead>
				
				<tbody>
					<tr v-for="(item,index) in zhida" :key="index">
						<td>
							<img v-if="index==0" src="../../../assets/img/jinpai.png" />
							<img v-else-if="index==1" src="../../../assets/img/yinpai.png" />
							<img v-else-if="index==2" src="../../../assets/img/tongpai.png" />
							<span v-else>{{index+1}}</span>
						</td>
						<td>
							<img :src="item.img" />
						</td>
						<td>
							<span>{{item.name}}</span>
							<span>排名无变化</span>
						</td>
						<td>
							{{item.fensi | guolv}}
						</td>
						<td>
							{{item.shu | guolv}}
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		
		<div class="fenye" style="text-align: center;">
			<el-pagination
			  @size-change="handleSizeChange"
			  @current-change="handleCurrentChange"
			  :hide-on-single-page="yindi"
			  :current-page="currentPage4"
			  :page-sizes="[100, 200, 300, 400]"
			  :page-size="100"
			  layout="total, sizes, prev, pager, next, jumper"
			  :total="4001">
			</el-pagination>
		</div>
		
	</div>
</template>

<script>
	export default{
		name:"zhibodarenbang",
		data(){
			return{
				shu:234232,
				fullscreenLoading:false,
				//分页
				yindi:true,//当数据是由一页时，就不显示分页器
				currentPage4: 1,
				
				column:[
					{title:'排名',key:'id',type:'text'},
					{title:'达人头像',key:'img',type:'image',width:100,height:100},
					{title:'名字',key:'name',type:'text'},
					{title:'粉丝量',key:'fensi',type:'text'},
					{title:'直播热度',key:'zhibo',type:'text'},
				],
				zhida:[
					{
						id:'1',
						name:'吉吉国王',
						img:'https://www.koltuita.com/wxxcx/img/val1.png',
						fensi:67867345,
						shu:234232,
					},
					{
						id:'2',
						name:'光头强',
						img:'https://www.koltuita.com/wxxcx/img/val4.png',
						fensi:265834,
						shu:894564,
					},
					{
						id:'3',
						name:'熊二',
						img:'https://www.koltuita.com/wxxcx/img/val1.png',
						fensi:346773,
						shu:97456,
					},
					{
						id:'4',
						name:'毛毛',
						img:'https://www.koltuita.com/wxxcx/img/val4.png',
						fensi:678345,
						shu:234547,
					},
					{
						id:'5',
						name:'熊大',
						img:'https://www.koltuita.com/wxxcx/img/val1.png',
						fensi:3456873,
						shu:567345,
					},
					{
						id:'6',
						name:'肥波',
						img:'https://www.koltuita.com/wxxcx/img/val4.png',
						fensi:235423,
						shu:12312,
					},
				],
				
				//日期范围选择
				pickerOptions: {
				  shortcuts: [{
					text: '最近一周',
					onClick(picker) {
					  const end = new Date();
					  const start = new Date();
					  start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
					  picker.$emit('pick', [start, end]);
					}
				  }, {
					text: '最近一个月',
					onClick(picker) {
					  const end = new Date();
					  const start = new Date();
					  start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
					  picker.$emit('pick', [start, end]);
					}
				  }, {
					text: '最近三个月',
					onClick(picker) {
					  const end = new Date();
					  const start = new Date();
					  start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
					  picker.$emit('pick', [start, end]);
					}
				  }]
				},
				value1: '',
				value2: '',
			}
		},
		//过滤器
		filters:{
			guolv(shuzi){
				  if(shuzi>0){
					var wan=parseInt(shuzi).toString();
					var qumo=wan%10000;
					//粉丝数改变
					if(wan.length<5){
						shuzi=wan;
					}else if(wan.length>4 && wan.length<=8){
						let fen_si=parseFloat(parseInt(wan/10000))+'.'+qumo.toString().substring(0,2)+'w';
						shuzi=fen_si;
					}else if(wan.length>8){
						let fen_si=parseFloat(parseInt(wan/100000000))+'.'+qumo.toString().substring(0,2)+'亿';
						shuzi=fen_si;
					}
				  }
				  return shuzi
			}
		},
		mounted:function(){
			//出现加载动画开始和结束
			this.$store.commit("startLoading")
			this.$store.commit("endLoading")
		},
		methods:{
			handleSizeChange(val) {
				console.log(`每页 ${val} 条`);
			},
			handleCurrentChange(val) {
				console.log(`当前页: ${val}`);
			},
			
			//点击导出表格数据到exe表
			xiazai(){
				this.fullscreenLoading = true;
				setTimeout(() => {
					this.fullscreenLoading = false;
					this.$message.success("数据导出成功！")
					
					this.table2excel(this.column, this.zhida, "直播达人榜单")//生成Excel表格，自动下载
				}, 2000);
			},
		}
	}
</script>

<style scoped="scoped" lang="scss">
	*{
		margin: 0;
		padding: 0;
	}
	.zhibodarenbang{
		
		.haowubang_header{
			padding: 0.8rem 2rem;
			background-color: #fff;
			border-bottom-left-radius:0.1rem ;
			border-bottom-right-radius:0.1rem ;
			
			.haowubang_header1{
				float: left;
				display: flex;
				justify-content: space-between;
				align-items: center;
				
				div:nth-of-type(1){
					color: #666;
					font-size: 0.4rem;
				}
				div:nth-of-type(2){
					color: #666;
					font-size: 0.4rem;
					margin: 0 1rem ;
				}
				div:nth-of-type(3){
					color: #666;
					font-size: 0.4rem;
					cursor: pointer;
					i{
						margin-left:0.2rem ;
					}
				}
				div:nth-of-type(3):hover{
					color: #0091FF;
				}
			}
			.haowubang_header2{
				float: right;
				display: flex;
				justify-content: space-between;
				align-items: center;
				
				span:nth-of-type(1){
					color: #333333;
					font-size: 0.4rem;
				}
				span:nth-of-type(2){
					color: #666666;
					font-size: 0.4rem;
					margin-right:1rem ;
				}
				span:nth-of-type(3){
					color: #666666;
					font-size: 0.4rem;
					padding: 0.1rem 0.3rem;
					border: 1px solid #D4D4D4;
					border-radius:0.1rem ;
					cursor: pointer;
					
					i{
						margin-right:0.2rem ;
					}
				}
				span:nth-of-type(3):hover{
					color: #fff;
					background-color: #0091FF;
				}
				
			}
		}
		.haowubang_header::after{
			content: "";
			display: block;
			clear: both;
		}
		
		.shanxing{
			
			.shanxing1{
				width: 50%;
				float: left;
				.shouye_tou1{
					height: 100%;
					box-sizing: border-box;
					float: left;
					position: relative;
					
					span{
						color: #000000;
						font-weight: 600;
						font-size: 0.45rem;
						display: block;
						margin-left:0.8rem ;
					}
					
					span::before{
						content: "";
						display: block;
						position: absolute;
						top: -0.1rem;
						left: 0;
						width: 0.3rem;
						height: 0.8rem;
						background-color: #1890FF;
					}
				}
				.shouye_tou1::after{
					content: "";
					display: block;
					clear: both;
				}
			}
			.shanxing1::after{
				content: "";
				display: block;
				clear: both;
			}
			.shanxing2{
				float: left;
				width: 50%;
				
				.shouye_tou2{
					height: 100%;
					box-sizing: border-box;
					float: left;
					position: relative;
					
					span{
						color: #000000;
						font-weight: 600;
						font-size: 0.45rem;
						display: block;
						margin-left:0.8rem ;
					}
					
					span::before{
						content: "";
						display: block;
						position: absolute;
						top: -0.1rem;
						left: 0;
						width: 0.3rem;
						height: 0.8rem;
						background-color: #1890FF;
					}
				}
				.shouye_tou2::after{
					content: "";
					display: block;
					clear: both;
				}
			}
		}
		.shanxing::after{
			content: "";
			display: block;
			clear: both;
		}
		
		.haowubiao{
			margin-top:1rem ;
			background-color: #fff;
			border-radius:0.1rem ;
			
			table{
				padding: 0.4rem 0.8rem;
				width: 100%;
				
				th{
					color: #333333;
					font-size: 0.42rem;
					font-weight: normal;
					padding: 0.8rem 0;
					text-align: center;
				}
				th:nth-of-type(3){
					text-align: left;
					width: 8rem;
				}
				td{
					padding: 0.8rem 0;
					color: #333333;
					font-size: 0.4rem;
					text-align: center;
				}
				tr:hover td{
					background-color: rgba(229,244,255,1);
				}
				td:nth-of-type(2){
					img{
						width: 1.4rem;
						height: 1.4rem;
						border-radius:50% ;
					}
				}
				
				td:nth-of-type(3){
					color: #333;
					text-decoration: none;
					display: flex;
					align-items: center;
					span:nth-of-type(1){
						margin-top:0.5rem ;
						margin-bottom:0.5rem ;
						display: block;
						overflow : hidden;
						text-overflow: ellipsis;
						display: -webkit-box; 
						-webkit-line-clamp: 1; /* 可以显示的行数，超出部分用...表示*/
						-webkit-box-orient: vertical;
					}
					span:nth-of-type(2){
						display: inline;
						padding: 0.1rem 0.3rem;
						border: 1px solid #999999;
						border-radius:0.1rem ;
						font-size: 0.35rem;
						margin-left:0.2rem ;
						white-space: nowrap;//强制不换行
					}
				}
				td:nth-of-type(3)::after{
					content: "";
					display: block;
					clear: both;
				}
				
				td:last-child{
					color: #333;
					font-size: 0.4rem;
					
					i{
						cursor: pointer;
					}
					
					i:nth-of-type(2){
						margin: 0 0.2rem;
					}
				}
				
			}
		}
	}
</style>
